package com.co.vote.web.controller.comment;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.co.server.constant.Constant;
import com.co.server.entity.vote.TComment;
import com.co.server.service.vote.TCommentService;
import com.co.vote.constant.HttpStatusCode;
import com.co.vote.utils.SessionUtil;

@Controller
@RequestMapping("/comment")
public class CommentController {
	
	@Resource
	TCommentService tCommentService;
	
	@ResponseBody
	@RequestMapping(value = "/add", method = { RequestMethod.GET,RequestMethod.POST })
	public Map<String, Object> add(Model model,HttpSession session,TComment tComment) {
		tComment.setUserId(SessionUtil.getUserId(session));
		tComment.setStatus(Constant.STATUS_ACTIVE);
		tComment.setCreateTime(new Date());
		tCommentService.add(tComment);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("code", HttpStatusCode.CODE_SUCCESS);
		result.put("tComment", tComment);
		result.put("user", SessionUtil.getUser(session));
		return result;
	}
}
